﻿'use strict';

/* httpPlus Service */
app.service('maskPlus', ['$window', '$q', function ($window, $q) {
    var tmpMaskPlus =
        '<div id="maskPlus" class="pos-abt w-full h-full mask-plus" style="top: 0;left:0; z-index: 7777;display: none;">' +
        '    <div id="maskPlusInner" class="animated fadeIn pos-abt w-full h-full bg-white-opacity" style="display: none;"></div>' +
        '    <div id="maskPlusSpinner" class="animated fade-in text-center pos-abt w-full" style="top: 40%;display: none;">' +
        '        <div class="spinner-wrap bg-dark lter wrapper-lg w-md" style="margin: 0 auto">' +
        '            <span class="fa fa-spinner fa-spin"></span> <small id="maskPlusText">加载中...</small>' +
        '        </div>' +
        '    </div>' +
        '</div>';

    var divMaskPlus = angular.element('div#maskPlus');
    if (divMaskPlus.length == 0)
        angular.element('body').append(tmpMaskPlus);
    divMaskPlus = angular.element('div#maskPlus');
    var divMaskPlusInner = angular.element('div#maskPlusInner');
    var divMaskPlusSpinner = angular.element('div#maskPlusSpinner');
    var txtMaskPlusText = angular.element('small#maskPlusText');
    var defaultMaskPlusText = '加载中...';

    var timeoutMaskPlus = undefined;

    this.showLoading = function (_msg) {
        // if (timeoutMaskPlus == undefined) {
            divMaskPlusSpinner.hide();
            divMaskPlusInner.hide();
            divMaskPlus.show();
            // timeoutMaskPlus = setTimeout(function () {
                // divMaskPlusInner.show();
                divMaskPlusSpinner.show();
                txtMaskPlusText.text(_msg || defaultMaskPlusText);
            // }, 2000);
        //} else {
        //    clearTimeout(timeoutMaskPlus);
        //    timeoutMaskPlus = undefined;
        //    this.showLoading(_msg);
        //}
    };

    this.hideLoading = function (_msg) {
        //clearTimeout(timeoutMaskPlus);
        //timeoutMaskPlus = undefined;

        divMaskPlusSpinner.hide();
        divMaskPlusInner.hide();
        divMaskPlus.hide();
    }
}]);